import {Map, tileLayer} from "leaflet"
import {
	$config
} from './config/gis_config'

export class LoadMap {
	constructor(viewDivId) {
		var me = this;
		me._viewDivId = viewDivId;
		me._map = Map(me._viewDivId);
		me.addTDTBaseLayer(me._map);
		var layer_gl = null; //管龄时态数据
		var mapServers = $config.gisConfig.mapServers;
		mapServers.forEach(function(item){
			if (item.url) {
				var layer = me.createLayer(item);
				if (layer) {
					me._map.add(layer);
				}
				if (item.id == "GL") {
					layer_gl = layer;
				}
			}
		})
	}
	
	function addTDTBaseLayer(map){
		
	}
	
	//创建图层
	createLayer(layerCreationProperties) {
		var layerType = layerCreationProperties.type.toLowerCase();
		var layer;
		switch (layerType) {
			case "tdt_webtilelayer": //加载在线地图（现在主要实现天地图的加载）
				layer = this.createTDTWebTiledLayer(layerCreationProperties);
				break;
			case "tiled":
				layer = this.createTiledLayer(layerCreationProperties);
				break;
			case "dynamic":
				layer = this.createDynamicLayer(layerCreationProperties);
				break;
			case "feature":
				layer = this.createFeatureLayer(layerCreationProperties);
				break;
			case "image":
				layer = this.createImageLayer(layerCreationProperties);
				break;
			case "baidu":
				layer = this.createBaiDuLayer(layerCreationProperties);
				break;
			case "tianditu_img":
				layer = this.createTianDiTiledYXMapServiceLayer_qg(layerCreationProperties);
				break;
			case "tianditu_img_label":
				layer = this.createTianDiTiledYXlableMapServiceLayer_qg(layerCreationProperties);
				break;
			case "tianditu":
				layer = this.createTianDiTiledMapServiceLayer_qg(layerCreationProperties);
				break;
			case "tianditu_label":
				layer = this.createTianDiTiledlableMapServiceLayer_qg(layerCreationProperties);
				break;
			default:
				layer = null;
		}
		return layer;
	}
}